import {
  DewDryTempture,
  DewEnthalpy,
  DewRelativeHumidity,
  DewWetTempture,
  DryEnthalpy,
  DryHumidity,
  DryRelativeHumidity,
  DryWetTempture,
  EnthalpyHumidity,
  EnthalpyRelativeHumidity,
  HumidityRelativeHumidity,
  WetRelativeHumidity,
  WetHumidity
} from './paramsStrategy'
import type { CalculationStrategy, WetAirStateParameter } from '../types'

/**
 * ### 策略工厂模式
 */
export default class StrategyFactory {
  private static strategies = new Map<string, new () => CalculationStrategy>([
    ['dewTemperature,dryTemperature', DewDryTempture],
    ['dewTemperature,enthalpy', DewEnthalpy],
    ['dewTemperature,relativeHumidity', DewRelativeHumidity],
    ['dewTemperature,wetTemperature', DewWetTempture],
    ['dryTemperature,enthalpy', DryEnthalpy],
    ['dryTemperature,humidity', DryHumidity],
    ['dryTemperature,wetTemperature', DryWetTempture],
    ['dryTemperature,relativeHumidity', DryRelativeHumidity],
    ['enthalpy,humidity', EnthalpyHumidity],
    ['enthalpy,relativeHumidity', EnthalpyRelativeHumidity],
    ['humidity,relativeHumidity', HumidityRelativeHumidity],
    ['humidity,wetTemperature', WetHumidity],
    ['relativeHumidity,wetTemperature', WetRelativeHumidity]
  ])

  /**
   * #### 根据参数获取计算策略
   * @param params 湿空气传入的状态参数，只能传2个
   * @returns
   */
  static getStrategy(params: WetAirStateParameter) {
    const key = Object.keys(params).sort().join(',')
    const strategyCls = this.strategies.get(key)
    if (!strategyCls) {
      throw new Error(`Unsupported parameter combination: ${key}`)
    }
    return new strategyCls()
  }
}
